package com.lyx.springmvc.dao;

import com.lyx.springmvc.pojo.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
@Repository
public class UserDAO {
    @Resource
    JdbcTemplate jdbcTemplate;

    public User getUser(String username, String password){
        String sql="select * from t_user where username= ? and password= ?";
        User user = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(User.class), username, password);
        return user;
    }
    public List<User> getUserByForm(User user){
        String sql="select * from t_user where username=? and password=? and sex=? and telphone=? and email=?";
        List<User> userList = jdbcTemplate.queryForList(sql, User.class, user.getUsername(), user.getPassword(),
                user.getSex(), user.getTelphone(), user.getEmail());
        return userList;
    }
    public int insert(User user){
        String sql="insert into t_user values(?,?,?,?,?,?)";
        int update = jdbcTemplate.update(sql, null, user.getUsername(), user.getPassword(),
                user.getSex(), user.getTelphone(), user.getEmail());

        return update;
    }
}

